<%@ page import="com.raise.drive.model.domain.Vehicle" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jspf/include.jspf" %>

<%--@elvariable id="form" type="com.raise.drive.web.form.SearchForm"--%>
<%--@elvariable id="dateFormat" type="java.lang.String"--%>

<tiles:insertDefinition name=".base">

    <tiles:putAttribute name="title">
        <fmt:message key="page.searchInstructor.title"/>
    </tiles:putAttribute>

    <tiles:putAttribute name="javascript">
        <script type="text/javascript">
            // <![CDATA[

            function resetGearBox() {
                $('gearBoxMT').checked = false;
                $('gearBoxAT').checked = false;
            }

            function resetGearBoxAny() {
                $('gearBoxAny').checked = false;
            }

            // ]]>
        </script>
    </tiles:putAttribute>

    <tiles:putAttribute name="menu">
        <%@ include file="/WEB-INF/jspf/anonymousMenu.jspf" %>
    </tiles:putAttribute>

    <tiles:putAttribute name="body">

        <form:form commandName="form">
            <div class="form-panel">
                <table>
                    <tr>
                        <td>
                            <span class="label"><fmt:message key="page.searchInstructor.name"/></span>
                        </td>
                        <td><form:input path="instructorSearchRequest.name"/></td>
                    </tr>
                    <tr>
                        <td>
                            <span class="label"><fmt:message key="page.searchInstructor.minPrice"/></span>
                        </td>
                        <td>
                            <form:input path="instructorSearchRequest.minPrice"/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span class="label"><fmt:message key="page.searchInstructor.maxPrice"/></span>
                        </td>
                        <td>
                            <form:input path="instructorSearchRequest.maxPrice"/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span class="label"><fmt:message key="entity.vehicle.gearBox"/></span>
                        </td>
                        <td>
                            <table>
                                <tr>
                                    <td>
                                        <input type="radio" id="gearBoxAny" onclick="resetGearBox();"
                                               <c:if test="${form.instructorSearchRequest.gearBox eq null}">checked="checked"</c:if>/>
                                        <fmt:message
                                                key="page.searchInstructor.anyGearBox"/>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <form:radiobutton id="gearBoxMT" path="instructorSearchRequest.gearBox"
                                                          value="<%=Vehicle.GearBox.MT%>" onclick="resetGearBoxAny();"/>
                                        <fmt:message
                                                key="entity.vehicle.gearBox.MT"/>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <form:radiobutton id="gearBoxAT" path="instructorSearchRequest.gearBox"
                                                          value="<%=Vehicle.GearBox.AT%>" onclick="resetGearBoxAny();"/>
                                        <fmt:message
                                                key="entity.vehicle.gearBox.AT"/>
                                    </td>
                                </tr>
                            </table>

                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <tags:submit key="page.searchInstructor.doSearch"/>
                        </td>
                    </tr>
                </table>
            </div>


            <c:choose>

                <c:when test="${fn:length(form.instructors) gt 0}">
                    <table>
                        <tr>
                            <th colspan="3">
                                <fmt:message key="page.searchInstructor.foundInstructors"/>
                            </th>
                        </tr>
                        <c:forEach items="${form.instructors}" var="instructor" varStatus="varStatus">
                            <%--<tr>
                                <td rowspan="4" <c:if test="${not varStatus.last}">class="border-delimeter"</c:if>>
                                    <!-- todo small image for avatar -->
                                    <img height="100"
                                         src="<c:url value="/Avatar.action?userId=${user.id}&amp;type=100"/>"
                                         alt="<fmt:message key="page.search.avatar"/>"/>
                                </td>
                                <td style="height: 10%">
                                    <a href="<c:url value="/ViewUser.action?userId=${user.id}&amp;back=Search.action"/>">
                                            ${user.displayName}
                                    </a>
                                </td>
                            </tr>--%>
                            <tr>
                                <td style="height: 10%">
                                        ${instructor.name}&nbsp;${instructor.surname}&nbsp;${instructor.patronymic}
                                </td>
                            </tr>
                            <tr>
                                <td style="height: 10%">
                                        ${instructor.shortDescription}
                                </td>
                            </tr>
                            <tr>
                                <td style="padding-left: 50px">
                                    <c:forEach items="${instructor.vehicles}" var="vehicle">
                                        <table>
                                            <tr>
                                                <td>
                                                        ${vehicle.vendor}&nbsp;${vehicle.model}
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                        ${vehicle.gearBox}
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <fmt:message key="entity.vehicle.additionalMirrors"/> <tags:yesNo
                                                        value="${vehicle.additionalMirrors}"/>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <fmt:message key="entity.vehicle.additionalPedals"/> <tags:yesNo
                                                        value="${vehicle.additionalPedals}"/>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <fmt:message
                                                            key="entity.vehicle.pricePerHour"/> ${vehicle.pricePerHour}
                                                </td>
                                            </tr>
                                        </table>

                                    </c:forEach>
                                </td>
                            </tr>

                        </c:forEach>
                    </table>
                    <div class="form-panel">
                        <spring:bind path="form.back">
                            <input type="submit" name="${status.expression}"
                                   value="<fmt:message key="common.back"/>"/>
                        </spring:bind>
                        <form:input path="instructorSearchRequest.page" size="7" maxlength="5"/>
                        <input type="submit" name="submit" value="<fmt:message key="page.searchInstructor.goToPage"/>"/>
                        <spring:bind path="form.forward">
                            <input type="submit" name="${status.expression}"
                                   value="<fmt:message key="common.forward"/>"/>
                        </spring:bind>
                    </div>
                </c:when>
                <c:otherwise>
                    <p>
                        <fmt:message key="page.search.noInstructorsFound"/>
                    </p>
                </c:otherwise>
            </c:choose>

        </form:form>


    </tiles:putAttribute>

</tiles:insertDefinition>
